<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>

<script>
    function demo()
    {
        console.log(this);
    }

    // 简化
    let test = () => {
        console.log(this);
    }

    let test2 = () => console.log('test2函数');

    test2();

    let obj = {
        name:'obj'
    };

    test.call(obj);
    demo.call(obj);

    var a = 1;

    function test3()
    {
        var a = 2;

        console.log('创建test3作用域');

        return function()
        {
            console.log(a += 1);
        }
    }

    let test4 = test3();

    // console.log(test4)
    test4();
    test4();
    test4();

    test4 = null;

    // 私有化 模块化
    const demo2 = (() => {
        let a = 1;
        let test = () => {
            console.log('demo2模块里的test函数');
        }

        return {
            a,
            test
        }
    })();

    console.log(demo2.a++);
    console.log(demo2.a++);
    console.log(demo2.a++);
    demo2.test();
</script>